#include "mymath.h"

double addUp(double a, double b) {
    fesetround(FE_UPWARD);
    return a+b;
}
double addDown(double a, double b) {
    fesetround(FE_DOWNWARD);
    return a+b;
}

double subUp(double a, double b)  {
    fesetround(FE_UPWARD);
    return a-b;
}
double subDown(double a, double b)  {
    fesetround(FE_DOWNWARD);
    return a-b;
}

double mulUp(double a, double b)  {
    fesetround(FE_UPWARD);
    return a*b;
}
double mulDown(double a, double b)  {
    fesetround(FE_DOWNWARD);
    return a*b;
}

double divUp(double a, double b)  {
    fesetround(FE_UPWARD);
    return a/b;
}
double divDown(double a, double b)  {
    fesetround(FE_DOWNWARD);
    return a/b;
}

double sqrtUp(double x)  {
    fesetround(FE_UPWARD);
    return sqrt(x);
}
double sqrtDown(double x)  {
    fesetround(FE_DOWNWARD);
    return sqrt(x);
}

double sinUp(double x) {
    fesetround(FE_UPWARD);
    return sin(x);
}

double sinDown(double x) {
    fesetround(FE_DOWNWARD);
    return sin(x);
}

double cosUp(double x) {
    fesetround(FE_UPWARD);
    return cos(x);
}

double cosDown(double x) {
    fesetround(FE_DOWNWARD);
    return cos(x);
}

double tanUp(double x) {
    fesetround(FE_UPWARD);
    return tan(x);
}

double tanDown(double x) {
    fesetround(FE_DOWNWARD);
    return tan(x);
}

double logUp(double x) {
    fesetround(FE_UPWARD);
    return log(x);
}

double logDown(double x) {
    fesetround(FE_DOWNWARD);
    return log(x);
}

int mygcd(int a, int b) {
    if (a%b == 0) return b;
    return mygcd(b, a%b);
}

int mylcm(int a, int b) {
    return a/mygcd(a, b)*b;
}
